#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
using namespace std;

const int chu=1000000007;
int main()
{
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
    int ncase;
    cin>>ncase;
    while(ncase--)
    {
        int n,t,k,a[1010],b[1010],tmp,tmp2,chu1=1;
        int i,j;
        cin>>n>>t>>k;
        for(i=1;i<=t;i++)
        {
            chu1 = chu1*k%chu;
        }
        for(i=1;i<=n;i++)
            cin>>a[i];
        for(i=1;i<=n;i++)
        {
            tmp=i-t%n;
            if(tmp<=0) tmp+=n;
            b[i]=a[tmp]*chu1%chu;
        }
        for(i=1;i<=n;i++)
        {
            cout<<b[i];
            if(i<n) cout<<" ";
        }
        cout<<endl;
    }
    return 0;
}
